package io.openaev.utils;

import io.openaev.database.model.Agent;
import io.openaev.database.model.Asset;
import io.openaev.database.model.AssetGroup;
import io.openaev.database.model.InjectExpectationSignature;
import io.openaev.model.expectation.VulnerabilityExpectation;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;

public class VulnerabilityExpectationUtils {

  public static VulnerabilityExpectation vulnerabilityExpectationForAgent(
      @Nullable final Double score,
      @NotBlank final String name,
      final String description,
      @NotNull final Agent agent,
      @NotNull final Asset asset,
      final AssetGroup assetGroup,
      final Long expirationTime,
      List<InjectExpectationSignature> injectExpectationSignatures) {
    VulnerabilityExpectation vulnerabilityExpectation = new VulnerabilityExpectation();
    vulnerabilityExpectation.setScore(Objects.requireNonNullElse(score, 100.0));
    vulnerabilityExpectation.setName(name);
    vulnerabilityExpectation.setDescription(description);
    vulnerabilityExpectation.setAgent(agent);
    vulnerabilityExpectation.setAsset(asset);
    vulnerabilityExpectation.setAssetGroup(assetGroup);
    vulnerabilityExpectation.setExpirationTime(expirationTime);
    vulnerabilityExpectation.setInjectExpectationSignatures(injectExpectationSignatures);
    return vulnerabilityExpectation;
  }

  public static VulnerabilityExpectation vulnerabilityExpectationForAsset(
      @Nullable final Double score,
      @NotBlank final String name,
      final String description,
      @NotNull final Asset asset,
      final AssetGroup assetGroup,
      final Long expirationTime) {
    VulnerabilityExpectation vulnerabilityExpectation = new VulnerabilityExpectation();
    vulnerabilityExpectation.setScore(Objects.requireNonNullElse(score, 100.0));
    vulnerabilityExpectation.setName(name);
    vulnerabilityExpectation.setDescription(description);
    vulnerabilityExpectation.setAsset(asset);
    vulnerabilityExpectation.setAssetGroup(assetGroup);
    vulnerabilityExpectation.setExpectationGroup(assetGroup != null);
    vulnerabilityExpectation.setExpirationTime(expirationTime);
    return vulnerabilityExpectation;
  }

  public static VulnerabilityExpectation vulnerabilityExpectationForAssetGroup(
      @Nullable final Double score,
      @NotBlank final String name,
      final String description,
      @NotNull final AssetGroup assetGroup,
      final boolean expectationGroup,
      final Long expirationTime) {
    VulnerabilityExpectation vulnerabilityExpectation = new VulnerabilityExpectation();
    vulnerabilityExpectation.setScore(Objects.requireNonNullElse(score, 100.0));
    vulnerabilityExpectation.setName(name);
    vulnerabilityExpectation.setDescription(description);
    vulnerabilityExpectation.setAssetGroup(assetGroup);
    vulnerabilityExpectation.setExpectationGroup(expectationGroup);
    vulnerabilityExpectation.setExpirationTime(expirationTime);
    return vulnerabilityExpectation;
  }
}
